home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir24 / jnos110g.zip / ARP.H < prev    next >
C/C++ Source or Header  |  1994-04-17  |  5KB  |  140 lines

  1. /* Mods by PA0GRI */
  2. #ifndef _ARP_H
  3. #define _ARP_H
  4.   
  5. #ifndef _GLOBAL_H
  6. #include "global.h"
  7. #endif
  8.   
  9. #ifndef _MBUF_H
  10. #include "mbuf.h"
  11. #endif
  12.   
  13. #ifndef _IFACE_H
  14. #include "iface.h"
  15. #endif
  16.   
  17. #ifndef _TIMER_H
  18. #include "timer.h"
  19. #endif
  20.   
  21. /* Lifetime of a valid ARP entry */
  22. #define ARPLIFE     900 /* 15 minutes */
  23. /* Lifetime of a pending ARP entry */
  24. #define PENDTIME    15  /* 15 seconds */
  25. /* Maximum number of datagrams in queue while pending an resolution */
  26. #define ARP_QUEUE   5   /* 5 packets max on queue */
  27.   
  28. /* ARP definitions (see RFC 826) */
  29.   
  30. #define ARPLEN  16      /* Size of ARP hdr, minus hardware addresses */
  31.   
  32. /* Address size definitions */
  33. #define IPALEN  4       /* Length in bytes of an IP address */
  34. /* Should be long enough below */
  35. #define MAXHWALEN   16 /* Maximum length of a hardware address */
  36.   
  37. /* ARP opcodes */
  38. #define ARP_REQUEST 1
  39. #define ARP_REPLY   2
  40. #define REVARP_REQUEST  3
  41. #define REVARP_REPLY    4
  42.   
  43. /* Hardware types */
  44. #define ARP_NETROM  0   /* Fake for NET/ROM (never actually sent) */
  45. #define ARP_ETHER   1   /* Assigned to 10 megabit Ethernet */
  46. #define ARP_EETHER  2   /* Assigned to experimental Ethernet */
  47. #define ARP_AX25    3   /* Assigned to AX.25 Level 2 */
  48. #define ARP_PRONET  4   /* Assigned to PROnet token ring */
  49. #define ARP_CHAOS   5   /* Assigned to Chaosnet */
  50. #define ARP_IEEE802 6   /* Who uses this? */
  51. #define ARP_ARCNET  7
  52. #define ARP_APPLETALK   8
  53. extern char *Arptypes[];    /* Type fields in ASCII, defined in arpcmd */
  54. #define NHWTYPES 9
  55.   
  56. /* Table of hardware types known to ARP */
  57. struct arp_type {
  58.     int16 hwalen;       /* Hardware length */
  59.     int16 iptype;       /* Hardware type field for IP */
  60.     int16 arptype;      /* Hardware type field for ARP */
  61.     int16 rarptype;     /* Hardware type field for RARP */
  62.     int16 pendtime;     /* # secs to wait pending response */
  63.     char *bdcst;        /* Hardware broadcast address */
  64.     char *(*format) __ARGS((char *,char *));
  65.                 /* Function that formats addresses */
  66.     int (*scan) __ARGS((char *,char *));
  67.                 /* Reverse of format */
  68. };
  69. extern struct arp_type far Arp_type[];
  70. #define NULLATYPE   (struct arp_type *)0
  71.   
  72. /* Format of an ARP request or reply packet. From p. 3 */
  73. struct arp {
  74.     int16 hardware;         /* Hardware type */
  75.     int16 protocol;         /* Protocol type */
  76.     char hwalen;            /* Hardware address length, bytes */
  77.     char pralen;            /* Length of protocol address */
  78.     int16 opcode;           /* ARP opcode (request/reply) */
  79.     char shwaddr[MAXHWALEN];    /* Sender hardware address field */
  80.     int32 sprotaddr;        /* Sender Protocol address field */
  81.     char thwaddr[MAXHWALEN];    /* Target hardware address field */
  82.     int32 tprotaddr;        /* Target protocol address field */
  83. };
  84.   
  85. /* Format of ARP table */
  86. struct arp_tab {
  87.     struct arp_tab *next;   /* Doubly-linked list pointers */
  88.     struct arp_tab *prev;
  89.     struct timer timer; /* Time until aging this entry */
  90.     struct mbuf *pending;   /* Queue of datagrams awaiting resolution */
  91.     int32 ip_addr;      /* IP Address, host order */
  92.     int16 hardware;     /* Hardware type */
  93.     char state;     /* (In)complete */
  94. #define ARP_PENDING 0
  95. #define ARP_VALID   1
  96.     char pub;       /* Respond to requests for this entry? */
  97.     char *hw_addr;      /* Hardware address */
  98.     struct iface *iface;    /* Interface to use route on -- sm6rpz */
  99. };
  100. #define NULLARP (struct arp_tab *)0
  101. extern struct arp_tab *Arp_tab[];
  102.   
  103. #ifdef LINUX
  104. #ifndef recv
  105. /* hack; we #define'd recv to j_recv to avoid stdc botch, so we need it here
  106.    else some things call this arp_stat.recv and others arp_stat.j_recv! */
  107. #include "socket.h"
  108. #endif
  109. #endif
  110. struct arp_stat {
  111.     unsigned recv;      /* Total number of ARP packets received */
  112.     unsigned badtype;   /* Incoming requests for unsupported hardware */
  113.     unsigned badlen;    /* Incoming length field(s) didn't match types */
  114.     unsigned badaddr;   /* Bogus incoming addresses */
  115.     unsigned inreq;     /* Incoming requests for us */
  116.     unsigned replies;   /* Replies sent */
  117.     unsigned outreq;    /* Outoging requests sent */
  118. };
  119. extern struct arp_stat Arp_stat, Rarp_stat;
  120.   
  121. /* In arp.c: */
  122. struct arp_tab *arp_add __ARGS((int32 ipaddr,int16 hardware,char *hw_addr,
  123. int pub,struct iface *iface));
  124. void arp_drop __ARGS((void *p));
  125. int arp_init __ARGS((unsigned int hwtype,int hwalen,int iptype,int arptype,
  126. int pendtime,char *bdcst,char *(*format) __ARGS((char *,char *)),
  127. int  (*scan) __ARGS((char *,char *)) ));
  128. void arp_input __ARGS((struct iface *iface,struct mbuf *bp));
  129. struct arp_tab *arp_lookup __ARGS((int16 hardware,int32 ipaddr,struct iface *iface));
  130. char *res_arp __ARGS((struct iface *iface,int16 hardware,int32 target,struct mbuf *bp));
  131.   
  132. /* In arphdr.c: */
  133. struct mbuf *htonarp __ARGS((struct arp *arp));
  134. int ntoharp __ARGS((struct arp *arp,struct mbuf **bpp));
  135.   
  136. /* In rarp.c: */
  137. void rarp_input __ARGS((struct iface *iface,struct mbuf *bp));
  138.   
  139. #endif /* _ARP_H */
  140.